home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / slock / slockfrm.pas < prev    next >
Pascal/Delphi Source File  |  1998-08-22  |  28KB  |  514 lines

  1. unit Slockfrm;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, registry, RegFrm, Slock, ExtCtrls, Menus;
  8.  
  9. type
  10.   TfrmMain = class(TForm)
  11.     btnRegister: TButton;
  12.     Slock1: TSlock;
  13.     grpStatus: TGroupBox;
  14.     lblStatus: TLabel;
  15.     lblStatusDisp: TLabel;
  16.     lblDaysLeft: TLabel;
  17.     lblDaysLeftDisp: TLabel;
  18.     lblStartsLeftDisp: TLabel;
  19.     lblExpiryDateDisp: TLabel;
  20.     lblProtType: TLabel;
  21.     lblProtTypeDisp: TLabel;
  22.     lblStartsLeft: TLabel;
  23.     lblExpiryDate: TLabel;
  24.     lblRegisteredTo: TLabel;
  25.     lblRegisteredToDisp: TLabel;
  26.     bvlStatus: TBevel;
  27.     lblGraceStartsLeft: TLabel;
  28.     lblGraceStartsLeftDisp: TLabel;
  29.     mnuMainMenu: TMainMenu;
  30.     mnmFile: TMenuItem;
  31.     mnpExit: TMenuItem;
  32.     mnmRegister: TMenuItem;
  33.     mnpRegNow: TMenuItem;
  34.     mnmFunction: TMenuItem;
  35.     mnpNormFunc: TMenuItem;
  36.     btnExit: TButton;
  37.     btnDelete: TButton;
  38.     procedure Slock1FirstStart(Sender: TObject);
  39.     procedure Slock1ClockMovedBack(Sender: TObject);
  40.     procedure Slock1Reminder(Sender: TObject);
  41.     procedure Slock1WrongUnlockCode(Sender: TObject);
  42.     procedure Slock1Expired(Sender: TObject);
  43.     procedure btnRegisterClick(Sender: TObject);
  44.     procedure Slock1Register(Sender: TObject);
  45.     procedure FormCreate(Sender: TObject);
  46.     procedure Slock1RegInfoChanged(Sender: TObject);
  47.     procedure Slock1InGracePeriod(Sender: TObject);
  48.     procedure Slock1RegWriteErr(Sender: TObject);
  49.     procedure mnpNormFuncClick(Sender: TObject);
  50.     procedure mnpExitClick(Sender: TObject);
  51.     procedure mnpRegNowClick(Sender: TObject);
  52.     procedure btnExitClick(Sender: TObject);
  53.     procedure Slock1Extend(Sender: TObject);
  54.     procedure Slock1TimedOut(Sender: TObject);
  55.     procedure btnDeleteClick(Sender: TObject);
  56.     procedure Slock1RegInfoTamper(Sender: TObject);
  57.   private
  58.     procedure UpdateStatus;
  59.   end;
  60.  
  61. var
  62.   frmMain: TfrmMain;
  63.  
  64. implementation
  65.  
  66. (* ToDo:
  67.  
  68.        Delete should also delete DLL Info
  69.        tidy up the starts properties (why do we need more than startsleft and graceleft? *)
  70.  
  71. {$R *.DFM}
  72.  
  73. {*******************************************************************************
  74. * Procedure : btnRegisterClick                                                 *
  75. ********************************************************************************
  76. * Purpose   : Opens up the window in which the registration information can    *
  77. *             be entered into                                                  *
  78. ********************************************************************************
  79. * Paramters : None                                                             *
  80. ********************************************************************************
  81. * Returns   : None                                                             *
  82. *******************************************************************************}
  83. procedure TfrmMain.btnRegisterClick(Sender: TObject);
  84. var
  85.      frmRegister: TfrmRegister;
  86. begin
  87.      // create the registration window
  88.      frmRegister := TfrmRegister.Create(self);
  89.  
  90.      // set the caption and show the window
  91.      frmRegister.Caption := 'Register ' + Caption;
  92.      frmRegister.ShowModal;
  93.  
  94.      // release the window
  95.      frmRegister.Free;
  96.  
  97.      // Update the status
  98.      UpdateStatus;
  99.  
  100. end; {btnRegisterClick}
  101.  
  102. {*******************************************************************************
  103. * Procedure : FormCreate                                                       *
  104. ********************************************************************************
  105. * Purpose   : We check the current status of the protection in the form create *
  106. *             of the main form. (Slock1.CheckProtection) The internal state of *
  107. *             Slock is set, and we then use 'UpdateStatus' to read the status  *
  108. *             of Slock out into the status display                             *
  109. ********************************************************************************
  110. * Paramters : None                                                             *
  111. ********************************************************************************
  112. * Returns   : None                                                             *
  113. *******************************************************************************}
  114. procedure TfrmMain.FormCreate(Sender: TObject);
  115. begin
  116.      // check the protection of the Slock component
  117.      SLock1.CheckProtection;
  118.  
  119.      // Update the status display and the state of the Buttons/Menupoints
  120.      UpdateStatus;
  121. end; {FormCreate}
  122.  
  123. {*******************************************************************************
  124. * Procedure : UpdateStatus                                                     *
  125. ********************************************************************************
  126. * Purpose   : Loads the internal status of the Slock component into the status *
  127. *             display. Also sets the state of the menus and buttons            *
  128. ********************************************************************************
  129. * Paramters : None                                                             *
  130. ********************************************************************************
  131. * Returns   : None                                                             *
  132. *******************************************************************************}
  133. procedure TfrmMain.UpdateStatus;
  134. begin
  135.      // load the status display
  136.      case Slock1.Status of
  137.      stNotExpired:
  138.           lblStatusDisp.Caption := 'Not Expired';
  139.      stExpired:
  140.           lblStatusDisp.Caption := 'Expired';
  141.      stGrace:
  142.           lblStatusDisp.Caption := 'Grace Period';
  143.      stRegistered:
  144.           lblStatusDisp.Caption := 'Registered';
  145.      end;
  146.  
  147.      // load the days/starts left display
  148.      case Slock1.ProtectionType of
  149.      ptStartCount:
  150.           begin
  151.                lblProtTypeDisp.Caption := 'Start Count';
  152.                lblDaysLeftDisp.Caption := 'N/A';
  153.                lblStartsLeftDisp.Caption := IntToStr(Slock1.TrialPeriod);
  154.                lblGraceStartsLeftDisp.Caption := IntToStr(Slock1.GracePeriod);
  155.                lblExpiryDateDisp.Caption := 'N/A';
  156.           end;
  157.      ptDayCount:
  158.           begin
  159.                lblProtTypeDisp.Caption := 'Day Count';
  160.                lblDaysLeftDisp.Caption := IntToStr(Slock1.TrialPeriod);
  161.                lblStartsLeftDisp.Caption := 'N/A';
  162.                lblGraceStartsLeftDisp.Caption := IntToStr(Slock1.GracePeriod);
  163.                lblExpiryDateDisp.Caption := DateToStr(Slock1.ExpiryDate);
  164.           end;
  165.      ptExpiryDate:
  166.           begin
  167.                lblProtTypeDisp.Caption := 'Expiry Date';
  168.                lblDaysLeftDisp.Caption := 'N/A';
  169.                lblStartsLeftDisp.Caption := 'N/A';
  170.                lblGraceStartsLeftDisp.Caption := IntToStr(Slock1.GracePeriod);
  171.                lblExpiryDateDisp.Caption := DateToStr(Slock1.ExpiryDate);
  172.           end;
  173.      ptTimed:
  174.           begin
  175.                lblProtTypeDisp.Caption := 'Timed';
  176.                lblDaysLeftDisp.Caption := 'N/A';
  177.                lblStartsLeftDisp.Caption := 'N/A';
  178.                lblGraceStartsLeftDisp.Caption := 'N/A';
  179.                lblExpiryDateDisp.Caption := 'N/A';
  180.           end;
  181.      ptDaysUsed:
  182.           begin
  183.                lblProtTypeDisp.Caption := 'Days Used';
  184.                lblDaysLeftDisp.Caption := 'N/A';
  185.                lblStartsLeftDisp.Caption := IntToStr(Slock1.TrialPeriod);
  186.                lblGraceStartsLeftDisp.Caption := IntToStr(Slock1.GracePeriod);
  187.                lblExpiryDateDisp.Caption := 'N/A';
  188.           end;
  189.      end;
  190.  
  191.      // load the registration information
  192.      if Slock1.Registered then
  193.      begin
  194.           lblRegisteredToDisp.Caption := Slock1.RegName;
  195.      end
  196.      else
  197.      begin
  198.           lblRegisteredToDisp.Caption := 'N/A';
  199.      end;
  200.  
  201.      // set the state of the buttons/menus
  202.      btnRegister.Enabled := not Slock1.Registered;
  203.      mnmRegister.Enabled := not Slock1.Registered;
  204.      mnmFunction.Enabled := (Slock1.